package com.hcloud.libupload.comom

import com.hcloud.libupload.bean.UploadHead
import com.hcloud.libupload.http.UploadHeadInterceptor

class UploadConfig(builder: Builder) {
    var loginKey: String
    var phone: String
    var boxId: String
    var upNode: String
    var maxUploadTaskSize: Int
    var maxUploadPartSize: Int
    var maxQueueSize: Int
    var partSize: Int
    var isLog: Boolean
    var isFastUpload: Boolean = true
    var reTryCount: Int
    var sdkType :Int
    var mainNode = ""
    var uploadHead: UploadHead

    class Builder {
        var loginKey = ""
        var phone = ""
        var boxId = ""
        var upNode = ""
        var maxUploadTaskSize = 2
        var maxUploadPartSize = 3
        var maxQueueSize = 10000
        var partSize = 1024 * 1024 * 5
        var isLog = false
        var isFastUpload = true
        var reTryCount = 0
        var sdkType = 0 //0多分片同时传  1分片依次传
        var mainNode = ""
        var uploadHead = UploadHead()

        fun build(): UploadConfig {
            return UploadConfig(this)
        }

        fun setLoginKey(loginKey: String): Builder {
            this.loginKey = loginKey
            return this
        }

        fun setUpNode(upNode: String): Builder {
            this.upNode = upNode
            return this
        }

        fun setPhone(phone: String): Builder {
            this.phone = phone
            return this
        }

        fun setBoxId(boxId: String): Builder {
            this.boxId = boxId
            return this
        }

        fun setLog(log: Boolean): Builder {
            isLog = log
            return this
        }

        fun setFastUpload(isFastUpload: Boolean): Builder {
            this.isFastUpload = isFastUpload
            return this
        }

        fun setReTryCount(reTryCount: Int): Builder {
            this.reTryCount = reTryCount
            return this
        }

        fun setMaxUploadTask(maxUploadTask: Int): Builder {
            this.maxUploadTaskSize = maxUploadTask
            return this
        }

        fun setMaxUploadPart(maxUploadPart: Int): Builder {
            this.maxUploadPartSize = maxUploadPart
            return this
        }

        fun setMaxQueueThread(maxQueueSize: Int): Builder {
            this.maxQueueSize = maxQueueSize
            return this
        }

        fun setPartSize(partSize: Int): Builder {
            this.partSize = partSize
            return this
        }

        fun setSdkType(sdkType: Int): Builder {
            this.sdkType = sdkType
            return this
        }

        fun setMainNode(mainNode : String): Builder {
            this.mainNode = mainNode
            return this
        }

        fun setHCloudHead(uploadHead: UploadHead): Builder {
            this.uploadHead = uploadHead
            return this
        }
    }

    init {
        loginKey = builder.loginKey
        phone = builder.phone
        boxId = builder.boxId
        upNode = builder.upNode
        maxUploadTaskSize = builder.maxUploadTaskSize
        maxUploadPartSize = builder.maxUploadPartSize
        maxQueueSize = builder.maxQueueSize
        partSize = builder.partSize
        isLog = builder.isLog
        isFastUpload = builder.isFastUpload
        reTryCount = builder.reTryCount
        sdkType = builder.sdkType
        mainNode = builder.mainNode
        uploadHead = builder.uploadHead
    }
}